package cn.signalpha.modules.social.service;

import cn.signalpha.core.tool.utils.BeanUtil;
import cn.signalpha.core.tool.utils.ObjectUtil;
import cn.signalpha.modules.social.entity.TopicTag;
import cn.signalpha.modules.social.excel.TopicTagExcel;
import cn.signalpha.modules.social.mapper.TopicTagMapper;
import cn.signalpha.modules.social.vo.TopicTagVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 服务类
 *
 * @author signalpha
 */
@Service
public class TopicTagService extends ServiceImpl<TopicTagMapper, TopicTag> {

	/**
	 * 自定义分页
	 */
    public IPage<TopicTagVO> selectTopicTagPage(IPage<TopicTagVO> page, Map<String, Object> params) {
        return page.setRecords(baseMapper.selectTopicTagPage(page, params));
    }

    /**
	 * 自定义导出
	 */
    public List<TopicTagExcel> selectTopicTagExcel(Map<String, Object> params) {
        return BeanUtil.copy(baseMapper.selectTopicTagPage(null, params), TopicTagExcel.class);
    }

    /**
	 * 自定义Wrappers
	 */
    public QueryWrapper<TopicTag> selectTopicTagWrapper(Map<String, Object> params) {
        QueryWrapper<TopicTag> wrapper = Wrappers.query();
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("id")), TopicTag::getId, params.get("id"));
        wrapper.lambda().like(ObjectUtil.isNotEmpty(params.get("name")), TopicTag::getName, params.get("name"));
		wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("isHot")), TopicTag::getIsHot, params.get("isHot"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("status")), TopicTag::getStatus, params.get("status"));
        wrapper.lambda().orderByDesc(TopicTag::getSort).orderByDesc(TopicTag::getId);
        return wrapper;
    }

}

